package com.weifeiyang.aidlserverdemo;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class MySingleService extends Service {
    private String TGA = "MySingleService";
    private MySingleNotifyCallBackInterface callBack;
    private int fromPosition;//当前服务

    public MySingleService() {
    }

    /**
     * MyServiceAidl.Stub类实现了IBinder和IRemoteService接口
     * 因此Stub的子类对象可以作为onBinder()方法的返回值.
     */
    public class MyBinder extends Binder implements MySingleServiceInterface{

        @Override
        public void registerCallBack(int from, MySingleNotifyCallBackInterface cb) {
            callBack = cb;
            fromPosition = from;
        }

        @Override
        public void unregisterCallBack(MySingleNotifyCallBackInterface cb) {

        }

        /*
           计算
         */
        @Override
        public void count() {
            Count count = new Count(fromPosition, callBack);
            count.add(3, 2);
        }

        /*
          People
        */
        @Override
        public void people() {
            People people = new People(fromPosition, callBack);
            people.eat();
        }

        @Override
        public void startService() {

        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.e(TGA, "onCreate");
    }

    @Override
    public IBinder onBind(Intent intent) {
        Log.e(TGA, "onBind");
        return new MyBinder();
    }

    @Override
    public void onDestroy() {
        Log.e(TGA, "onDestroy");
        super.onDestroy();
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.e(TGA, "onUnbind");
        return super.onUnbind(intent);
    }

    @Override
    public void onRebind(Intent intent) {
        Log.e(TGA, "onRebind");
        super.onRebind(intent);
    }

}
